<?php include "antet.php"; include "func.php";

if (isset($_SESSION["user"][0], $_GET["town"]))
{
	$_GET["town"]=clean($_GET["town"]);
	check_a($_GET["town"]);
	$town=town($_GET["town"]); if ($town[1]!=$_SESSION["user"][0]) {header('Location: login.php'); die();}
	$faction=faction($_SESSION["user"][10]);
	$units=units($faction[0]);
	$aq=get_a($town[0]);
$lim=explode("-", $town[11]);
$res=explode("-", $town[10]);
	$prod=explode("-", $town[9]); $lim=explode("-", $town[11]);
	$out=explode("-", $buildings[15][5]);

	$data=explode("-", $town[8]); $army=explode("-", $town[7]); $gen=explode("-", $town[15]);
	if (isset($_GET["target"])) {$target=town($_GET["target"]); $target=$target[2];} else $target="";

} else {
	header ( 'Location: login.php' );
	die ();
}
kepala($title." - ".$lang['dispatch']);
?>
<script type="text/javascript">
var res_start0=<?php echo floor($res[0]);?>; var res_start1=<?php echo floor($res[1]);?>; var res_start2=<?php echo floor($res[2]);?>; var res_start3=<?php echo floor($res[3]);?>; var res_start4=<?php echo floor($res[4]);?>;
var res_limit0=<?php echo $lim[0];?>; var res_limit1=<?php echo $lim[1];?>; var res_limit2=<?php echo $lim[1];?>; var res_limit3=<?php echo $lim[1];?>; var res_limit4=<?php echo $lim[2];?>;
var res_ph0=<?php echo ($prod[0]-$town[3]-$town[12]);?>; var res_ph1=<?php echo ($prod[1]);?>; var res_ph2=<?php echo ($prod[2]);?>; var res_ph3=<?php echo ($prod[3]);?>; var res_ph4=<?php echo ($prod[4]);?>;
var res_sec0=0; var res_sec1=0; var res_sec2=0; var res_sec3=0; var res_sec4=0;
</script>
<?php
			
		$output = "";
		$output .= buildingheader($to,$buildings,$data,$lim,$town);
		$output .= showproduction($town,$lim);
			$extra = box("finish.png", $lang['buildingMaxLvl'], $lang['buildingMaxLvl']);
				$output = "<table class='q_table' style='border-collapse: collapse; text-indent: 0; text-align: center; margin-left: auto; margin-right: auto;' width='600' border='0'>
				<tr>
					<td width='20%'><img src='".$imgs.$fimgs."crossroad.png' width='75' title='".$lang['crossroad']."'><br>".$lang['crossroad']."</td>
					<td><h1>".$lang['crossroad']."</h1>Dispatch your army to anywhere.<hr size='1' width='75%' color='orange'>".$extra."</td>
				</tr>
				</table>";

			if (count($aq)) echo $lang['deployQueue'].":</br>";
			for ($i=0; $i<count($aq); $i++)
			{
				$tget=town($aq[$i][1]);
				switch($aq[$i][2])
				{
					case 0: $what="reinforce"; break;
					case 1: $what="raid"; break;
					case 2: $what="attack"; break;
					case 3: $what="spy"; break;
				}
				echo "[<a class='q_link' href='cancel_a.php?town=".$_GET["town"]."&id=".$aq[$i][5]."'>x</a>] ".$what." ".$tget[2]." - <span id='".$i."'>".$aq[$i][0]."</span><script type='text/javascript'> var id=new Array(50); timer('".$i."', 'dispatch.php?town=".$_GET["town"]."'); </script></br>";
			}
			?>
			<?php echo $lang['sendTroopsTo'] ?>
		<table class="q_table" style="border-collapse: collapse" width="400"
			border="1">
			<tr>
				<td><?php echo $lang['icon'] ?></td>
				<td><?php echo $lang['available'] ?></td>
				<td><?php echo $lang['send'] ?></td>
			</tr>
			<?php
			echo "<form name='dispatch' method='post' action='sendt.php?town=".$_GET["town"]."'>
<select class='dropdown' name='type'>
<option value='0'>".$lang['reinforce']."</option>
<option value='1'>".$lang['raid']."</option>
<option value='2'>".$lang['attack']."</option>
<option value='3'>".$lang['spy']."</option>
</select> ".$lang['townOf']." <input class='textbox' name='target' type='text' value=\"".$target."\"></br></br>
<select class='dropdown' name='general'><option value='0'>".$lang['withoutGeneral']."</option><option value='1'>".$lang['withGeneral']."</option></select> ".$lang['using']." <select class='dropdown' name='formation'><option value='0'>".$lang['standard']."</option><option value='1'>".$lang['offensive']."</option><option value='2'>".$lang['defensive']."</option></select> ".$lang['formation'].".</br>";
			if (!$gen[1]) label($lang['noGeneral']); else if (!$gen[0]) label($lang['generalAway']);
			for ($i=0; $i<13; $i++) echo "<tr><td><img src='".$imgs.$fimgs."2".$i.".gif' title='".$units[$i][2]."'></td><td>".$army[$i]."</td><td><input class='textbox' name='q_".$i."' type='text' size='4' maxlength='4' value='1'></td></tr>";
			echo "</table>";
			?>
			<input class='button' type='submit' name='button0'
				value='<?php echo $lang['send'] ?>'>
			</form>
			</br>
			</br>
			[
			<a class='q_link' href='csim.php?town=<?php echo $_GET["town"]; ?>'><?php echo $lang['cSim'] ?></a>
			] [
			<a class='q_link' href='gen.php?town=<?php echo $_GET["town"]; ?>'><?php echo $lang['general'] ?></a>
			]
<?php			
		$output .= ads(1,"bottom");
		$output .= about(); 
		echo $output;
?>
